package com.demo.proxy;

import cn.hutool.aop.aspects.SimpleAspect;

import java.lang.reflect.Method;

public class CalculatorAspect extends SimpleAspect {

    @Override
    public boolean before(Object target, Method method, Object[] args) {

        System.out.println("参数1: " + args[0]);
        System.out.println("参数2: " + args[1]);
        // 获取当前代理的类名称和方法名称
        String className = method.getDeclaringClass().getName();
        String methodName = method.getName();
        System.out.println(className + "." + methodName + "动态代理开始!!");

        return super.before(target, method, args);
    }

    @Override
    public boolean after(Object target, Method method, Object[] args, Object returnVal) {
        System.out.println("动态代理返回-->" + returnVal);
        return super.after(target, method, args, returnVal);
    }

    @Override
    public boolean afterException(Object target, Method method, Object[] args, Throwable e) {
        return super.afterException(target, method, args, e);
    }
}
